﻿using System.Windows;
using System.Windows.Media;
using uTrade.Core;

namespace uTrade.Controls
{
    public class VerticalLine : DrawObjBase
    {
        public DataSeries Data;

        public Pen LinePen = new Pen(Brushes.BlueViolet, 1);

        protected override int TotalItemCount { get => Data.Count; }

        //绘制垂线
        protected override void DrawObj(DrawingContext dc)
        {
            // 1.Get Max and min
            double highest = 0;
            double lowest = double.MaxValue;

            var h = Data.Highest(drawItemStartIndex, drawItemCount);
            if (h > highest)
            {
                highest = h;
            }
            var l = Data.Lowest(drawItemStartIndex, drawItemCount);
            if (l < lowest)
            {
                lowest = l;
            }

            var vals = Data;
            for (var i = 0; i < drawItemCount; ++i)
            {
                int itemIndex = drawItemStartIndex + i;
                double xoffset = (int)(i * (itemWidth + itemSpace)) + 0.5 + ChartStartX;
                double yoffset = (1.0 - vals[itemIndex] / highest) * ChartHeight + 0.5 + ChartStartY;

                var pen = LinePen;
                //TODO
                //if (priceInfo.PriceList[itemIndex].Open > priceInfo.PriceList[itemIndex].Close)
                //{
                //    pen.Brush = Brushes.Red;
                //}
                //else
                //{
                //    pen.Brush = Brushes.Green;
                //}
                dc.DrawLine(pen, new Point(xoffset + itemWidth / 2, yoffset), new Point(xoffset + itemWidth / 2, ChartStartY + ChartHeight));
            }
        }
    }
}